import hashlib
import json
import random

import requests


def make_hash(password):
    m = hashlib.sha256()
    m.update(password.encode())
    return m.hexdigest()


def get_verfir_code(length=4):
    code_list = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBMN'
    return ''.join(random.choices(code_list, k=length))


def gen_mobile_code(lengh=6):
    all_chars = '0123456789'
    return ''.join(random.choices(all_chars, k=lengh))


def send_mobile_code(tel, code):
    resp = requests.post(
        url='http://sms-api.luosimao.com/v1/send.json',
        auth=('api', 'key-d752503b8db92317a2642771cec1d9b0'),
        data={
            'mobile': tel,
            'message': f'你的短信验证码是{code},打死也不呢告诉别人！【Python小课】'
        },
    verify = False
    )
    return json.loads(resp.text)
